package com.wtwd.campus.encryptnetty;

import io.netty.channel.Channel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class EncryptChannelMap {

    private static Map<String, Channel> map = new ConcurrentHashMap<String, Channel>();

    public static void add(String clientId, Channel channel) {
        map.put(clientId, channel);
    }

    public static Channel get(String clientId) {
        return map.get(clientId);
    }

    public static void removeByKey(String key) {
        map.remove(key);
    }

    public static String getKey(Channel channel) {
        String key = "";
        for (Map.Entry<String, Channel> entry : map.entrySet()) {
            if (entry.getValue() == channel) {
                key = entry.getKey();
            }
        }
        return key;
    }

}
